package com.aiyige.utils;

import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.EditText;

public class EditTextAutoMoveCursorToEndFocusChangeListener implements View.OnFocusChangeListener {
    Handler mainHandler = new Handler(Looper.getMainLooper());

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if ((v instanceof EditText) && hasFocus) {
            final EditText editText = (EditText) v;
            mainHandler.post(new Runnable() {
                @Override
                public void run() {
                    editText.setSelection(editText.getText().length());
                }
            });
        }
    }
}
